package com.handong.handserialprogram.module.voice;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;

import com.handong.handserialprogram.R;
import com.handong.handserialprogram.constants.KeyConstant;
import com.handong.handserialprogram.model.entities.PersonEntity;
import com.handong.handserialprogram.module.base.BackStackActivity;
import com.handong.handserialprogram.module.base.BaseActivity;
import com.handong.handserialprogram.module.base.BaseView;
import com.handong.handserialprogram.module.createmission.CreateMissionFragment;
import com.handong.handserialprogram.module.createmission.recordtask.CriminalFragment;
import com.handong.handserialprogram.module.createmission.recordtask.RecordTaskFragment;
import com.handong.handserialprogram.service.PlayService;
import com.handong.handserialprogram.utils.AppCache;
import com.handong.handserialprogram.utils.CallBackUtil;

import net.arvin.selector.data.ConstantData;

import java.io.FileNotFoundException;
import java.util.ArrayList;

public class VoiceActivity extends BackStackActivity implements BaseView {

    private static final int NEED_SIZE = 4;
    private CallBackUtil.OnSelectedPhotoListener onSelectedPhotoListener;
    /**
     * 注册回调接口的方法，供外部调用
     * @param onSelectedPhotoListener
     */
    public void setOnSelectedPhotoListener(CallBackUtil.OnSelectedPhotoListener onSelectedPhotoListener) {
        this.onSelectedPhotoListener = onSelectedPhotoListener;
    }

    @Override
    protected int getContentViewID() {
        return R.layout.activity_create_mission;
    }



    @Override
    protected void initViewDataRes() {
        Bundle bundle=getIntent().getExtras();
        TestVoiceActivity test=TestVoiceActivity.newInstance();
        test.mMissionId=bundle.getString(KeyConstant.MISSION_ID);
        addFirstFragment(test, R.id.createMissionContainer, NEED_SIZE);
        setResult(RESULT_OK);
    }


    public void openActWithFadeOut(Class<? extends BaseActivity> cls, Bundle bundle) {
        Intent intent = new Intent(this, cls);
        intent.putExtras(bundle);
        startActivity(intent);
        finish();
        overridePendingTransition(R.anim.push_left_in, R.anim.anim_fade_out);
    }

    @Override
    public void finish() {
        super.finish();
        overridePendingTransition(R.anim.anim_no, R.anim.push_right_out);

    }
    public ArrayList<String> selectedPictures = new ArrayList<>();
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            if (requestCode == 1001) {
                ArrayList<String> backPics = data.getStringArrayListExtra(ConstantData.KEY_BACK_PICTURES);
                ArrayList<String> backVideos = data.getStringArrayListExtra(ConstantData.KEY_BACK_VIDEOS);
                selectedPictures.clear();
                if (backPics != null && backPics.size() > 0) {
                    selectedPictures.addAll(backPics);
                }
                if (backVideos != null && backVideos.size() > 0) {
                    selectedPictures.addAll(backVideos);
                }
                if (((backVideos != null && backVideos.size() > 0)||(backPics != null && backPics.size() > 0))&&onSelectedPhotoListener != null)
                {
                    try {
                        onSelectedPhotoListener.onSelected(selectedPictures);
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    }
                }
            }
        }

    }
}
